//
//  TopicCommentObj.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/7.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "TopicCommentObj.h"
#import "UrlLabel.h"

@implementation TopicCommentObj

-(void)setObjByDict:(NSDictionary *)dict
{
    self.commentId = SafeGetStringValue([dict objectForKey:@"id"]);
    self.topicId = SafeGetStringValue([dict objectForKey:@"topicId"]);
    self.userId = SafeGetStringValue([dict objectForKey:@"userId"]);
    self.content = SafeGetStringValue([dict objectForKey:@"content"]);
    self.nickname = SafeGetStringValue([dict objectForKey:@"nickname"]);
    
    NSTimeInterval time = SafeGetDoubleValue([dict objectForKey:@"createTime"])/1000.0f;
    NSDate *oDate = [NSDate dateWithTimeIntervalSince1970:time];
    NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
    NSTimeZone* destinationTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:oDate];
    NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:oDate];
    NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
    NSDate* currentDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:oDate];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];// 创建一个时间格式化对象
    [dateFormatter setDateFormat:@"MM.dd hh:mm"];//设定时间格式,这里可以设置成自己需要的格式
    self.createTime = [dateFormatter stringFromDate:currentDate];//将时间转化成字符串

    self.contentLab = [[UrlLabel alloc] initWithFrame:CGRectMake(0, 0, IPHONEWIDTH - 60 - 20, 1000*15)];
    self.contentLab.numberOfLines = 1000;
    [self.contentLab setText:self.content textColor:FBEE_COLOR_TEXT font:[UIFont systemFontOfSize:15.0f] urlColor:FBEE_COLOR_BLUE urlTapBlock:^(NSURL *url) {
        
        UIApplication *application = [UIApplication sharedApplication];
        if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
            [application openURL:url options:@{} completionHandler:nil];
        } else {
            [application openURL:url];
        }
    }];
    [self.contentLab sizeToFit];
    
    /*
     评论模块高度计算
     
     边距       10
     正文上部    44
     正文下部    35
     */
    self.contentH = self.contentLab.height;
    self.height += 10 + 44 + 35 + self.contentH;
    
}

@end
